function vmd_Dspectra(fbase, fnum)
%
%   vmd_Uspectra(fbase, fnum)
%
%   Reads file with density distribution.
%   Creates two text files with specral data.
%
%   Input:
%        fbase   base of file number (runname)
%        fnum    file number
%
%   Domain information and colormap limits are edited in the file.

%---------------------------------------------------------

% system size

jx=96; jy=96; jz=32;


% physics paramters

Lx=900; Ly=900; kz=0.34; nz=1;


%---------------------------------------------------------

  dkz = kz/nz;
  dkx = 2*pi / Lx;
  dky = 2*pi / Ly;

  ixc = jx/2+1;
  iyc = min(jy/2+1, jy);

  fn = num2str(fnum,'%04d');


  %-- read density components

  fname = [fbase, '.dn.', fn];
  fid  = fopen(fname, 'rb');
  dn   = fread(fid, jx*jy*jz, 'double'); fclose(fid);
  dn   = reshape(dn, jz,jy,jx);



  %-- output files --

  fname = [fbase, '.dnFTx.', fn, '.txt'];
  fidx = fopen(fname, 'wt');

  fprintf(fidx,'%% z-averaged x-spectra of density\n');
  fprintf(fidx,'%% 1.kx   2.<|dn(kx)|^2>  \n')

  %-- x-spectra

  %fk  = fftn( dn(:,iyc,:) )/(jx*jz);
  %fksq = fk.*conj(fk);
  %dnsq = sum(fksq,1)/jz;

  fk  = fftn( dn(:,:,:) )/(jx*jy*jz);
  fksq = fk.*conj(fk);
  fksq = reshape(sum(fksq,1)/jz, jy,jx);

  imagesc(fftshift(log(fksq)))

  dnsq = fksq(1,:);

  for i=1:jx/2
     k=(i-1)*dkx;
     fprintf(fidx, "%14.6e %14.6e\n", k, dnsq(i));
  end
  
  fclose(fidx);


end
